//
//  CommunityCollectionViewCell.m
//  PTravel
//
//  Created by dllo on 15/11/15.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "CommunityCollectionViewCell.h"

@implementation CommunityCollectionViewCell

- (void)dealloc
{
    [_image release];
    [_title release];
    [_postsNum release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubViews];
    }
    return self;

}

- (void)createSubViews
{
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(15*WIDTH, 6*HEGIHT, 38*WIDTH, 38*HEGIHT)];
    [self.contentView addSubview:self.image];
    [_image release];
    
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x + 50*WIDTH, 6*HEGIHT, BOUNDS.size.width/2-60*WIDTH, 20*HEGIHT)];
    self.title.text = @"亚洲";
    self.title.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.title];
    [_title release];
    
    self.postsNum = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.origin.x + 50*WIDTH, self.title.frame.origin.y+20*HEGIHT, BOUNDS.size.width/2-60*WIDTH, 20*HEGIHT)];
    [self.contentView addSubview:self.postsNum];
    self.postsNum.text = @"帖子";
    self.postsNum.font = [UIFont systemFontOfSize:10];
    [_postsNum release];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10*WIDTH, 55*HEGIHT, BOUNDS.size.width/2-10*WIDTH, 1)];
    line.backgroundColor = [UIColor colorWithWhite:0.574 alpha:1.000];
    [self.contentView addSubview:line];
    [line release];
//
    UIView *linee = [[UIView alloc] initWithFrame:CGRectMake(BOUNDS.size.width/2+10*WIDTH, 5*HEGIHT, 1, 40*HEGIHT)];
    linee.backgroundColor = [UIColor colorWithWhite:0.557 alpha:1.000];
    [self.contentView addSubview:linee];
    [linee release];

}

- (void)setCommunity:(Community *)community
{
    if (_community != community) {
        [_community release];
        _community = [community retain];
    }
    
    self.title.text = community.name;
    self.postsNum.text = [NSString stringWithFormat:@"%@个帖子",community.total_threads];
    self.title.textColor = TEXTCOLOR;
    self.postsNum.textColor = TEXTCOLOR;
    NSURL *url = [NSURL URLWithString:community.photo];
    [self.image sd_setImageWithURL:url placeholderImage:IMAGE];
}

@end
